<form id="dictFieldForm" class="form-horizontal"  method="post">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h5 class="blue">新增枚举</h5>
    </div>

    <div class="modal-body">
        <input type="hidden" name="id" id="id" value="${dictField.id!}">
        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="fieldName">枚举名:</label>
            <div class="col-xs-12 col-sm-9">
                <div class="clearfix">
                    <input type="text" name="fieldName" id="fieldName" class="col-xs-12 col-sm-4" value="${dictField.fieldName!}"/>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="fieldTitle">枚举中文名:</label>
            <div class="col-xs-12 col-sm-9">
                <div class="clearfix">
                    <input type="text" name="fieldTitle" id="fieldTitle" class="col-xs-12 col-sm-4 required" value="${dictField.fieldTitle!}"/>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="modifyEnable">是否可修改:</label>
            <div class="col-xs-5 col-sm-9">
                <div class="clearfix">
                    <div>
                        <select class="chosen-select form-control" name="modifyEnable" id="modifyEnable" data-placeholder="Choose a State...">
                            <option value="1">允许</option>
                            <option value="0">不允许</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
    <div class="modal-footer center">
        <button type="submit" class="btn btn-sm btn-success"><i class="ace-icon fa fa-check"></i> 保存</button>
        <button type="button" class="btn btn-sm" data-dismiss="modal"><i class="ace-icon fa fa-times"></i> 取消</button>
    </div>

</form>
<script src="${ctx}/static/admin/assets/js/jquery.validate.js"></script>
<script src="${ctx}/static/admin/assets/js/jquery.validate.messages_zh.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $(".date-picker").datepicker({
            language : 'zh-CN',
            autoclose: true,
            todayHighlight: true
        });

        $("#dictFieldForm").validate({
            rules:{fieldName:{required:true,
                remote:{
                    url: "/admin/system/dictField/check.do", //后台处理程序
                    type: "get",  //数据发送方式
                    data:  {                     //要传递的数据
                        fieldName: function() { return $("#fieldName").val();},
                        id: function() { return $("#id").val();}
                    }
                }}},
            messages:{fieldName:{
                                 required:"请填写枚举名",
                                 remote:"该枚举名已存在"

            }},
            errorElement: 'div',
            errorClass: 'help-block',
            focusInvalid: true,
            highlight: function (e) {
                $(e).closest('.form-group').removeClass('has-info').addClass('has-error');
            },
            success: function (e) {
                $(e).closest('.form-group').removeClass('has-error');//.addClass('has-info');
                $(e).remove();
            },
            errorPlacement: function (error, element) {
                if(element.is('input[type=checkbox]') || element.is('input[type=radio]')) {
                    var controls = element.closest('div[class*="col-"]');
                    if(controls.find(':checkbox,:radio').length > 1) controls.append(error);
                    else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
                }
                else if(element.is('.select2')) {
                    error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
                }
                else if(element.is('.chosen-select')) {
                    error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
                }
                else error.insertAfter(element.parent());
            },

            submitHandler: function (form) {
                $.ajax({
                    type: "POST",
                    url:"${ctx}/admin/system/dictField/save.do",
                    data:$("#dictFieldForm").serialize(),
                    dataType: 'text',
                    success: function(msg){
                        var msg = eval("("+msg+")");
                        if(msg.result == "success"){
                            window.location="${refer!}";
                        }else{
                            alert(msg.messages);
                            //bootbox.alert(msg.messages);
                        }
                    },
                    error: function(){
                        bootbox.alert("保存失败");
                    }
                });
            },
            invalidHandler: function (form) {
            }
        })

    });
</script>